package ai.people.netmon.framework.domain.userconfig.request;

import ai.people.netmon.framework.domain.userconfig.entity.UserCollectConfigAccount;
import ai.people.netmon.framework.model.request.PageKeyWordsRequest;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotBlank;

/**
 * @author zhenglin
 * @date 2022/2/28
 */
@Data
public class AccountQueryRequest extends PageKeyWordsRequest {
    /**
     * 创建用户唯一标识
     */
    @NotBlank(message = "userId不能为空")
    private String userId;

    public LambdaQueryWrapper<UserCollectConfigAccount> createQueryWrapper(){
        LambdaQueryWrapper<UserCollectConfigAccount> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(UserCollectConfigAccount::getUserId, this.userId);
        String searchKeywords = getSearchKeywords();
        if (StringUtils.isNotBlank(searchKeywords)) {
            wrapper.and(x -> x.like(UserCollectConfigAccount::getAccount, searchKeywords).or().like(UserCollectConfigAccount::getInfoType, searchKeywords).or().like(UserCollectConfigAccount::getAppName, searchKeywords));
        }
        return wrapper;
    }

}
